# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-fiber-local
pkgver=1.0.0
pkgrel=1
pkgdesc='Provides a class-level mixin to make fiber local state easy'
arch=(any)
url='https://github.com/socketry/fiber-local'
license=(MIT)
depends=(ruby)
checkdepends=(ruby-rspec)
options=(!emptydirs)
source=(https://github.com/socketry/fiber-local/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('6391f85334ab6bf103e0ded475cc4b59909a068dd63cc45e80bb0753cb6cc5dd')

prepare() {
  cd fiber-local-$pkgver
  sed '/covered/d' -i fiber-local.gemspec spec/spec_helper.rb
  rm gems.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd fiber-local-$pkgver
  gem build fiber-local.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    fiber-local-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd fiber-local-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rspec
}

package() {
  cd fiber-local-$pkgver
  cp -a tmp_install/* "$pkgdir"/
}
